package cn.highedu.spring.config;

import cn.highedu.spring.bean.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@Configuration
public class MyConfig {
    @Bean
    public AccountRepository accountRepository(){
        return new JdbcAccountRepository();
    }
    @Bean
    public TransferService transferService(){
        TransferServiceImpl service = new TransferServiceImpl();
        service.setAccountRepository(accountRepository());
        return service;
    }
    @Bean
    public AccountService accountService(){
        return new AccountServiceImpl(accountRepository());
    }

    /**
     * 作用域为 prototype，每次调用都会创建一个新的实例
     * @return Action
     */
    @Bean
    @Scope("prototype")
    public Action action(){
        return new Action();
    }
}
